package ouisseuk.gui;

import com.flexycore.iphone.coregraphics.CGRect;
import com.flexycore.iphone.uikit.UIColor;
import com.flexycore.iphone.uikit.UIKeyboardAppearance;
import com.flexycore.iphone.uikit.UIKeyboardType;
import com.flexycore.iphone.uikit.UINavigationController;
import com.flexycore.iphone.uikit.UIReturnKeyType;
import com.flexycore.iphone.uikit.UITextField;
import com.flexycore.iphone.uikit.UIView;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
public class SearchView extends UIView {
	/**
	 * 
	 */
	private UINavigationController nav;
	private UITextField loginField;

	/**
	 * Constructor
	 * 
	 * @param nav
	 */
	public SearchView(final UINavigationController nav) {
		super();
		initWithFrame(CGRect.CGRectMake(0, 0, 320, 416));
		this.nav = nav;

		/*
		 * login TextField
		 */
		loginField = new UITextField();
		loginField.initWithFrame(CGRect.CGRectMake(40, 50, 240, 30));
		// loginField.setBorderStyle(UITextBorderStyle.UITextBorderStyleRoundedRect);
		loginField.setBackgroundColor(UIColor.whiteColor());
		loginField.setKeyboardType(UIKeyboardType.UIKeyboardTypeASCIICapable);
		loginField
				.setKeyboardAppearance(UIKeyboardAppearance.UIKeyboardAppearanceAlert);
		loginField.setReturnKeyType(UIReturnKeyType.UIReturnKeyDone);
		loginField.setPlaceholder("artist, album name or both");
		// loginField.setClearsOnBeginEditing(true);
		loginField.setAdjustsFontSizeToFitWidth(true);
		addSubview(loginField);

		// /*
		// * Button
		// */
		// UIButton button = new UIButton() {
		// @Override
		// public void controlEvent() {
		// showSearchResults();
		// }
		// };
		// button.initWithFrame(CGRect.CGRectMake(40, 90, 240, 30));
		// button.setTitleForState("Search", 0);
		// button.setTitleColorForState(UIColor.darkGrayColor(), 0);
		// button.setTitleColorForState(UIColor.whiteColor(), 1 << 0);
		// button
		// .addTargetActionForControlEvents(UIControlEvents.UIControlEventTouchUpInside);
		// addSubview(button);

	}

	public void showSearchResults() {
		SearchResultsViewController viewController = new SearchResultsViewController(
				nav, loginField.text());
		nav.pushViewControllerAnimated(viewController, true);
	}

}
